﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace AyuBookmark.WinForm.Dialogs
{
    /// <summary>
    /// 隐私政策确认对话框
    /// </summary>
    public partial class PrivacyDialog : Form
    {
        private const string PrivacyText = @"感谢您使用AyuBookmark！我们非常重视您的隐私。

1. 数据收集
- 我们仅收集必要的书签数据用于同步功能
- 不会收集任何浏览历史或个人身份信息

2. 数据使用
- 数据仅用于提供核心功能
- 不会将数据用于广告或分析

3. 数据存储
- 本地数据加密存储
- 云端数据采用AES-256加密

4. 权限控制
- 您可以随时导出或删除数据
- 提供完整的权限管理功能

请阅读完整隐私政策后选择是否继续使用：";

        // UI控件声明
        private RichTextBox txtPrivacy;
        private Panel panel;
        private Button btnAccept;
        private Button btnDecline;
        private LinkLabel linkLabel;

        public bool PrivacyAccepted { get; private set; }

        public PrivacyDialog()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            // 窗体设置
            this.SuspendLayout();
            this.Text = "隐私政策";
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.ClientSize = new Size(500, 400);
            this.BackColor = SystemColors.Window;

            // 隐私文本控件
            this.txtPrivacy = new RichTextBox();
            this.txtPrivacy.Text = PrivacyText;
            this.txtPrivacy.ReadOnly = true;
            this.txtPrivacy.BorderStyle = BorderStyle.None;
            this.txtPrivacy.BackColor = SystemColors.Window;
            this.txtPrivacy.ScrollBars = RichTextBoxScrollBars.Vertical;
            this.txtPrivacy.Dock = DockStyle.Fill;
            this.txtPrivacy.Margin = new Padding(20);
            this.txtPrivacy.Font = new Font("Microsoft YaHei", 9.75f);

            // 按钮面板
            this.panel = new Panel();
            this.panel.Dock = DockStyle.Bottom;
            this.panel.Height = 60;
            this.panel.BackColor = SystemColors.Control;

            // 接受按钮
            this.btnAccept = new Button();
            this.btnAccept.Text = "接受并继续";
            this.btnAccept.DialogResult = DialogResult.OK;
            this.btnAccept.Size = new Size(120, 35);
            this.btnAccept.Location = new Point(250, 15);
            this.btnAccept.Font = new Font("Microsoft YaHei", 9f, FontStyle.Bold);
            this.btnAccept.Click += (s, e) =>
            {
                this.PrivacyAccepted = true;
                this.Close();
            };

            // 拒绝按钮
            this.btnDecline = new Button();
            this.btnDecline.Text = "拒绝并退出";
            this.btnDecline.DialogResult = DialogResult.Cancel;
            this.btnDecline.Size = new Size(120, 35);
            this.btnDecline.Location = new Point(380, 15);
            this.btnDecline.Font = new Font("Microsoft YaHei", 9f);
            this.btnDecline.Click += (s, e) =>
            {
                this.PrivacyAccepted = false;
                this.Close();
            };

            // 查看完整政策链接
            this.linkLabel = new LinkLabel();
            this.linkLabel.Text = "查看完整隐私政策";
            this.linkLabel.AutoSize = true;
            this.linkLabel.Location = new Point(20, 25);
            this.linkLabel.LinkColor = Color.FromArgb(0, 102, 204);
            this.linkLabel.LinkClicked += (s, e) =>
            {
                System.Diagnostics.Process.Start("https://example.com/privacy");
            };

            // 添加控件到面板
            this.panel.Controls.Add(this.linkLabel);
            this.panel.Controls.Add(this.btnAccept);
            this.panel.Controls.Add(this.btnDecline);

            // 添加控件到窗体
            this.Controls.Add(this.txtPrivacy);
            this.Controls.Add(this.panel);

            this.ResumeLayout(false);
        }

        public static bool ShowPrivacyDialog(IWin32Window owner)
        {
            using (var dialog = new PrivacyDialog())
            {
                return dialog.ShowDialog(owner) == DialogResult.OK && dialog.PrivacyAccepted;
            }
        }
    }
}